home *** CD-ROM | disk | FTP | other *** search
- Path: ecf2.puc.edu!bivey
- From: bivey@ecf2.puc.edu (Bruce Ivey)
- Newsgroups: comp.lang.c
- Subject: Re: Keyboard input: C's equivalent to BASIC's Inkey$
- Date: 25 Jan 1996 03:33:27 GMT
- Organization: CRL Dialup Internet Access
- Message-ID: <4e6tm7$ntc@nntp.crl.com>
- References: <Pine.SUN.3.91.960111212844.17033A@suntan>
- NNTP-Posting-Host: ecf2.puc.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Carlos Diaz (CS) (cdiaz@eng.usf.edu) wrote:
- : Hi! Can someone tell me what the C equivalent of BASIC's Inkey$ command
- : is? In particular, I'm looking to translate the following BASIC code to
- : C. It's the old, "wait for a key- if there is no key do something else
- : then wait for a key, etc".
-
- In Borland C/C++, try
-
- int readKey()
- {
- int key = 0;
-
- if (kbhit())
- {
- key = getch(); /* a key was pressed; read it */
- if (key == 0) /* if zero, this is a two-char Fn key */
- key = -getch(); /* read 2nd char & return as negative */
- } /* to signal that this is an F-key */
- return key;
- }
-